#@adminLayout() #define main()

<body class="white-bg">
	<form class="form-horizontal m" id="form_add"  method="post" >
		<div class="form-group">
			<div class="col-sm-10">
           		<table id="jqGrid"></table>
           	</div>
		</div>
	</form>

	<div class="row" id="btn">
		<div class="col-sm-offset-3 col-sm-10">
			<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
			<button type="button" class="btn btn-sm btn-primary" onclick="openSetting()"><i class="fa fa-pencil-square-o"></i>参数管理 </button>
		</div>
	</div>
	
	 <script type="text/javascript">
        var prefix = "#(ctx)/sysoption";
		
        $(function(){
			bindData();
		});
        function submitHandler() {
			var options = {
				dataType : "json",
				url :prefix + "/save",
				data:{data:getTableData()},
				success : function(data) {
					layer.msg(data.msg);
					reloadData();
				}
			};
			$("#form_add").ajaxSubmit(options);
	    }
        
		let $table = $('#jqGrid');
    	var lastsel3;
        function bindData()
        {
        	$table.jqGrid({
                url: prefix + "/list",
                datatype: "json",
                styleUI: 'Bootstrap',//设置jqgrid的全局样式为bootstrap样式 
                colModel: [
                    { label: 'id', name: 'id', width: 65,hidden: true,key:true},
                    { label: '参数名', name: 'name', width: 100},
                    { label: '参数值', name: 'value', width: 500,editable : true,edittype: 'text'},
                    { label: '参数说明', name: 'cdesc', width: 200}
                ],
                width:$(window).width()-60,
                shrinkToFit:false,
                autoScroll: true, 
                height:260,
                cellsubmit: "clientArray",
                multiselect: false,
                onSelectRow : function(id) {
                    if (id && id !== lastsel3) {
                    	if (lastsel3 != null && lastsel3 != "" && lastsel3.length > 0) {
                    		$table.jqGrid('saveRow', lastsel3);//保存上一行
                        }
                      	$table.jqGrid('editRow', id, true);
                      	lastsel3 = id;
                    }
                    else
                    {
                      	lastsel3 = '';
                    }
                  }
            });
        }
        
        //获取行数据
        function getTableData(){
        	$table.jqGrid('saveRow', lastsel3);
        	var data=$table.jqGrid('getRowData');
            return JSON.stringify(data);
        }
        

        function reloadData()
        {
        	$table.jqGrid('clearGridData');  //清空表格
        	$table.jqGrid('setGridParam',{  // 重新加载数据
        		url: prefix + "/list",
                datatype: "json"
        	}).trigger("reloadGrid");
        }
        
        
        function openSetting()
        {
        	var url=prefix+"/set";
        	$.modal.openFull("参数设置", url, 800, 500);
        }
    </script>
</body>
#end